package com.weijie.relaxed.net;

import java.util.HashMap;

import com.weijie.relaxed.App;
import com.weijie.relaxed.net.RequestFactory.JPostStringRequest;
import com.weijie.relaxed.net.RequestFactory.JStringRequest;

/** 
 * Api
 * @author weijie 
 * @version 创建时间：2015年3月18日 下午2:50:02 
 */
public class Api {

	public static final String register(App app,StringListener listener,String username,String password) {
		String tag = "register";
		HashMap<String,String> params = new HashMap<String,String>();
		
		
		HashMap<String,String> headers = new HashMap<String,String>();
		headers.put("Content-Type","application/json");
		
		/*try {
			params.put("username",URLEncoder.encode("GuoJason", "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}*/
		params.put("username",username);
		params.put("password",password);
		JPostStringRequest request = RequestFactory.createStringHttpPost("https://a1.easemob.com/529844698/relaxed/users",
				params, headers, listener, tag);
		
		app.getRequestQueue().add(request);
		return tag;
	}
	
	public static final String getToken(App app,StringListener listener) {
		String tag = "getToken";
		HashMap<String,String> params = new HashMap<String,String>();
		
		
		HashMap<String,String> headers = new HashMap<String,String>();
		headers.put("Content-Type","application/json");
		
		/*try {
			params.put("username",URLEncoder.encode("GuoJason", "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}*/
		params.put("grant_type","client_credentials");
		params.put("client_id","YXA6mNBPsM0aEeSu621sjDRZBQ");
		params.put("client_secret","YXA6l0bVBZocOgJLnzCU-o_Sp5FgJVw");
		JPostStringRequest request = RequestFactory.createStringHttpPost("https://a1.easemob.com/529844698/relaxed/token",
				params, headers, listener, tag);
		
		app.getRequestQueue().add(request);
		return tag;
	}
	
	public static final String getFriendList(App app,StringListener listener,String token,String username) {
		String tag = "getFriendList";
		HashMap<String,String> headers = new HashMap<String,String>();
		headers.put("Authorization","Bearer "+token);
		JStringRequest request = RequestFactory.createStringHttpGet("https://a1.easemob.com/529844698/relaxed/users/"+username+"/contacts/users",
				null, headers, listener, tag);
		
		app.getRequestQueue().add(request);
		return tag;
	}
	
}
